package com.yeyks.controller.other;

import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.param.hotel.VipOpenCityAddParam;
import com.yeyks.common.param.hotel.VipOpenCityUpdateParam;
import com.yeyks.hotel.dal.domain.HotelRecommendCity;
import com.yeyks.vip.dal.domain.VipOpenCity;
import com.yeyks.vip.service.VipOpenCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 开放城市控制类
 * @author dagny
 * @date 2020/4/7 0007 10:02
 */
@Api(tags = "v4.4.0 开放城市管理")
@RestController
@RequestMapping("/vip/open/city")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class VipOpenCityController {

    private final VipOpenCityService vipOpenCityService;

    @ApiOperation(value = "v4.4 --> 开放城市列表", response = HotelRecommendCity.class)
    @PostMapping(value = "/list")
    public AjaxResponseBody<List<VipOpenCity>> cityList() {
        return AjaxResponseBody.success(vipOpenCityService.list());
    }

    @ApiOperation(value = "v4.4 --> 开放城市新增", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/add")
    public AjaxResponseBody<Boolean> cityAdd(@Valid VipOpenCityAddParam param) {

        Boolean flag = vipOpenCityService.insertCity(param);

        return AjaxResponseBody.success(flag);
    }

    @ApiOperation(value = "v4.4 --> 开放城市编辑", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/update")
    public AjaxResponseBody<Boolean> cityUpdate(@Valid VipOpenCityUpdateParam param) {

        Boolean flag = vipOpenCityService.updateCity(param);
        return AjaxResponseBody.success(flag);
    }

    @ApiOperation(value = "v4.4 --> 开放城市删除", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/del")
    public AjaxResponseBody<Boolean> cityDel(Integer id) {
        Arguments.intIsNull(id, "推荐城市id不能为空");
        return AjaxResponseBody.success(vipOpenCityService.removeById(id));
    }

    @ApiOperation(value = "v4.4 --> 同步拼音城市接口信息", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/sync/pinyin")
    public AjaxResponseBody<Boolean> syncPinyin() {

        return AjaxResponseBody.success(vipOpenCityService.syncAllPinyin());
    }
}
